//
//  GLWebViewVC.m
//  Jingcai
//
//  Created by lishuai on 15/11/7.
//  Copyright © 2015年 xiaogangpao. All rights reserved.
//

#import "GLWebViewVC.h"

@interface GLWebViewVC ()<UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *webview;

@end

@implementation GLWebViewVC

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.navigationItem.title = @"webview";
    }
    return self;
}

- (void)setupWebview{
    _webview = [[UIWebView alloc] initWithFrame:self.view.bounds];
    _webview.delegate = self;
    
    [self.view addSubview:_webview];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupWebview];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:self.url];
    
    [_webview loadRequest:urlRequest];
    
    [_webview reload];
    
}

#pragma mark - webview Delegate
- (void)webViewDidStartLoad:(UIWebView *)webView {
    NSLog(@"start");
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSString *theTitle=[webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    self.title = theTitle;
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error {
    NSLog(@"fail");
}


@end
